<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=640px,user-scalable=no,target-densitydpi=device-dpi" />
		<link rel="stylesheet" href="../css/css.css" type="text/css" />
		<script type="text/javascript" src='../js/jquery.min.js'></script>
		<script type="text/javascript" src='../js/main_in.js'></script>
		<script type="text/javascript" src='../js/common.js'></script>
		<title>基础资料</title>
		<script type="text/javascript">
			var loginname = window.localStorage["loginname"];
			var uid = window.localStorage["uid"];
			var cpid = window.localStorage["cpid"];
			var x = getUrlParam('x');
                if(x == null){
                    x=1;
                }
			$(function(){
				start_search();
				end_search();
				car_search();
				if(x == 2){
                    $(".pass_body").hide();
                    $(".pass_body_2").show();
                    $(".app_head_left").css("border-bottom","none");
                    $(".app_head_right").css("border-bottom","3px solid #B2D7F0");
                }if(x == 3){
                    $(".pass_body").hide();
                    $(".pass_body_3").show();
                    $(".app_head_left").css("border-bottom","none");
                    $(".app_head_right2").css("border-bottom","3px solid #B2D7F0");
                }
                $(".app_head_left").click(function(){
                    $(".pass_body").hide();
                    $(".pass_body_1").show();
                    $(".app_head_right").css("border-bottom","none");
                    $(".app_head_right2").css("border-bottom","none");
                    $(".app_head_left").css("border-bottom","3px solid #B2D7F0");
                    x = 1;
                });
                
                $(".app_head_right").click(function(){
                    $(".pass_body").hide();
                    $(".pass_body_2").show();
                    $(".app_head_left").css("border-bottom","none");
                    $(".app_head_right2").css("border-bottom","none");
                    $(".app_head_right").css("border-bottom","3px solid #B2D7F0");
                    x = 2;
                });
                
                $(".app_head_right2").click(function(){
                    $(".pass_body").hide();
                    $(".pass_body_3").show();
                    $(".app_head_left").css("border-bottom","none");
                    $(".app_head_right").css("border-bottom","none");
                    $(".app_head_right2").css("border-bottom","3px solid #B2D7F0");
                    x = 3;
                });
                
                $("body").on('click', ".bgsearch_main", function() {
                    if ($(this).hasClass('main_in_input_hide_cur')) {
                        var dos = 1;
                    }
                    $('.bgsearch_main').removeClass('main_in_input_hide_cur');
                    $(".bgsearch_main").find(".disnone").hide();
                    if (dos != 1) {
                        $(this).find(".disnone").show();
                        $(this).addClass('main_in_input_hide_cur');
                    }
                    
                });
                
                $("#do_add").click(function(){
                	if(x == 1){
                		clicked("./custadd.html");
                	}
                	if(x == 2){
                		clicked("./addradd.html");
                	}
                	if(x == 3){
                		clicked("./caradd.html");
                	}
                	
                });
                
                $("#do_edit").click(function(){
                    var hid = $(".main_in_input_hide_cur").find('.bgsearch_main_hang').eq(0).find('.bgsearch_main_right').html();
                    if(hid != undefined){
                    	if(x == 1){
                    		clicked("custedit.html?hid="+hid)
                    	}
                    	if(x == 2){
                    		clicked("addredit.html?hid="+hid)
                    	}
                    	if(x == 3){
                    		clicked("caredit.html?hid="+hid)
                    	}
                    }
                });
                
			});
			
			function start_search(){
				$.ajax({
                    url : "http://api.unair.cn/api/CustomerWarehousesBL?createby=" + loginname + "&cpid=" + cpid ,
                    type: "GET",
                    success: function(data) {
//                        data = eval("(" + data.ResTable + ")");
                        var item = '';
                        $.each(data, function(k, v) {
                            v.Customer.CustomerName = typeof (v.Customer.CustomerName) == 'undefined' ? '' : v.Customer.CustomerName;
                            v.Customer.CustomerName = v.Customer.CustomerName == null ? '' : v.Customer.CustomerName;
                            v.Customer.CustomerTel = typeof (v.Customer.CustomerTel) == 'undefined' ? '' : v.Customer.CustomerTel;
                            v.Customer.CustomerTel = v.Customer.CustomerTel == null ? '' : v.Customer.CustomerTel;
                            v.Customer.CustomerContact = typeof (v.Customer.CustomerContact) == 'undefined' ? '' : v.Customer.CustomerContact;
                            v.Customer.CustomerContact = v.Customer.CustomerContact == null ? '' : v.Customer.CustomerContact;
                            item += '<div class="bgsearch_main">' +
                                        '<div class="bgsearch_main_hang"  style="display:none">' +
                                            '<div class="bgsearch_main_left"></div>' +
                                            '<div class="bgsearch_main_right">' + v.Customer.CustomerID + '</div>' +
                                        '</div>' +
                                        '<div class="bgsearch_main_hang">' +
                                            '<div class="bgsearch_main_left">客户名称:</div>' +
                                            '<div class="bgsearch_main_right">' + v.Customer.CustomerName + '</div>' +
                                        '</div>' +
                                        '<div class="bgsearch_main_hang">' +
                                            '<div class="bgsearch_main_left">联系人:</div>' +
                                            '<div class="bgsearch_main_right">' + v.Customer.CustomerContact + '</div>' +
                                        '</div>' +
                                        '<div class="bgsearch_main_hang">' +
                                            '<div class="bgsearch_main_left">联系电话:</div>' +
                                            '<div class="bgsearch_main_right">' + v.Customer.CustomerTel + '</div>' +
                                        '</div>' +
                                        '<div class="bgsearch_main_hang disnone">' +
                                            '<div class="bgsearch_main_left">发货城市：</div>' +
                                            '<div class="bgsearch_main_right">' + v.Customer.CustomerCityName + '</div>' +
                                        '</div>' +
                                        '<div class="bgsearch_main_hang disnone">' +
                                            '<div class="bgsearch_main_left">详细地址：</div>' +
                                            '<div class="bgsearch_main_right">' + v.Customer.CustomerAddr + '</div>' +
                                        '</div>';
                            var qq = 1;        
                            $.each(v.Warehouses,function(kk,vv){
                                item +=     '<div class="bgsearch_main_hang disnone">' +
                                                '<div class="bgsearch_main_left">收货单位'+qq+'</div>' +
                                                '<div class="bgsearch_main_right">' + vv.WarehouseName + '</div>' +
                                            '</div>' +
                                            '<div class="bgsearch_main_hang disnone">' +
                                                '<div class="bgsearch_main_left">联系人:</div>' +
                                                '<div class="bgsearch_main_right">' + vv.WarehouseContact + '</div>' +
                                            '</div>' +
                                            '<div class="bgsearch_main_hang disnone">' +
                                                '<div class="bgsearch_main_left">联系电话</div>' +
                                                '<div class="bgsearch_main_right">' + vv.WarehouseTel + '</div>' +
                                            '</div>';
                                qq++;
                            });
                            item += '</div>';
                        });
                        $(".pass_body_1").append(item);
                    },
                    error: function(data) {
//                        alert(JSON.stringify(data));
                    }
                });
			}
			
			function end_search(){
				var where2 =  "CreateBy = '"+loginname+"' and Type = 2";
                var body = {"TableName": "Address", "PKName": "ID", "PageSize": "15", 'pageCurrent': 1, "where": where2 };

                $.ajax({
                    url: "http://api.unair.cn/api/PagingQuery",
                    type: "POST",
                    data: body,
                    success: function(data) {
                        data = eval("(" + data.ResTable + ")");
                        var item = '';
                        $.each(data, function(k, v) {
                            v.CustomerName = typeof (v.CustomerName) == 'undefined' ? '' : v.CustomerName;
                            v.CustomerName = v.CustomerName == null ? '' : v.CustomerName;
                            v.Contact = typeof (v.Contact) == 'undefined' ? '' : v.Contact;
                            v.Contact = v.Contact == null ? '' : v.Contact;
                            v.ContactTel = typeof (v.ContactTel) == 'undefined' ? '' : v.ContactTel;
                            v.ContactTel = v.ContactTel == null ? '' : v.ContactTel;
                             item += '<div class="bgsearch_main">' +
                                        '<div class="bgsearch_main_hang"  style="display:none">' +
                                            '<div class="bgsearch_main_left"></div>' +
                                            '<div class="bgsearch_main_right">' + v.ID + '</div>' +
                                        '</div>' +
                                        '<div class="bgsearch_main_hang">' +
                                            '<div class="bgsearch_main_left">收货单位</div>' +
                                            '<div class="bgsearch_main_right">' + v.Warehouse + '</div>' +
                                        '</div>' +
                                        '<div class="bgsearch_main_hang">' +
                                            '<div class="bgsearch_main_left">联系人:</div>' +
                                            '<div class="bgsearch_main_right">' + v.Contact + '</div>' +
                                        '</div>' +
                                        '<div class="bgsearch_main_hang">' +
                                            '<div class="bgsearch_main_left">联系电话:</div>' +
                                            '<div class="bgsearch_main_right">' + v.ContactTel + '</div>' +
                                        '</div>' +
                                    '</div>';
                        });
                        $(".pass_body_2").append(item);
                    },
                    error: function(data) {
//                        alert(data)
                    }
                });
			}
			
			function car_search(){
				$.ajax({
                    url: "http://api.unair.cn/api/DriverBL?userID=" + uid + "&driverId=0",
                    type: "GET",
                    data: {},
                    success: function(data) {
                        var item = '';
                        $.each(data, function(k, v) {
                            v.PlateNo2 = typeof (v.PlateNo2) == 'undefined' ? '' : v.PlateNo2;
                            v.PlateNo2 = v.PlateNo2 == null ? '' : v.PlateNo2;
                            v.DriverName = typeof (v.DriverName) == 'undefined' ? '' : v.DriverName;
                            v.DriverName = v.DriverName == null ? '' : v.DriverName;
                            v.Mobile = typeof (v.Mobile) == 'undefined' ? '' : v.Mobile;
                            v.Mobile = v.Mobile == null ? '' : v.Mobile;
                             item += '<div class="bgsearch_main">' +
                                        '<div class="bgsearch_main_hang"  style="display:none">' +
                                            '<div class="bgsearch_main_left"></div>' +
                                            '<div class="bgsearch_main_right">' + v.DriverID + '</div>' +
                                        '</div>' +
                                        '<div class="bgsearch_main_hang">' +
                                            '<div class="bgsearch_main_left">车牌号</div>' +
                                            '<div class="bgsearch_main_right">' + v.PlateNo + '</div>' +
                                        '</div>' +
                                        '<div class="bgsearch_main_hang">' +
                                            '<div class="bgsearch_main_left">车挂号</div>' +
                                            '<div class="bgsearch_main_right">' + v.PlateNo2 + '</div>' +
                                        '</div>' +
                                        '<div class="bgsearch_main_hang">' +
                                            '<div class="bgsearch_main_left">姓名:</div>' +
                                            '<div class="bgsearch_main_right">' + v.DriverName + '</div>' +
                                        '</div>' +
                                        '<div class="bgsearch_main_hang">' +
                                            '<div class="bgsearch_main_left">手机号:</div>' +
                                            '<div class="bgsearch_main_right">' + v.Mobile + '</div>' +
                                        '</div>' +
                                    '</div>';
                        });
                        $(".pass_body_3").append(item);
                    },
                    error: function(data) {
//                        alert(data)
                    }
                });
			}
		</script>
	</head>
	<body>
		<div class="app_head">
            <div class="app_prev bg_back" onclick="clicked('../index.html')"><img src="../img/arrow.png" /></div>
            <div class="app_head_text">资料维护</div>
            <div class="app_prev"></div>
        </div>
        <div class="passenger_head">
            <div class="app_head_left">客户资料</div>
            <div class="app_head_cen">|</div>
            <div class="app_head_right">收货单位</div>
            <div class="app_head_cen">|</div>
            <div class="app_head_right2">司机信息</div>
        </div>
        <div class="pass_body_1 pass_body"></div>
        <div style="display: none" class="pass_body_2 pass_body"></div>
        <div style="display: none" class="pass_body_3 pass_body"></div>
        <div style="margin-top: 30px;">
                <div class="bg_submit" id="do_add">新&nbsp;增</div>
                <div class="bg_back_class" id="do_edit" >修&nbsp;改</div>
            </div>
	</body>
</html>
